import 'package:flutter/material.dart';
import 'package:shopping_group/base/base_constant.dart';
import 'package:shopping_group/modle/person/entity/userid_name_phone_entity.dart';
import 'package:shopping_group/res/colors.dart';
import 'package:shopping_group/utils/widget_utils.dart';

class DownTuanYouPage extends StatefulWidget {
  final List<UserIdNamePhoneEntity> downlistEntity;
  DownTuanYouPage({Key key, this.downlistEntity}) : super(key: key);

  @override
  _DownTuanYouPageState createState() => _DownTuanYouPageState();
}

class _DownTuanYouPageState extends State<DownTuanYouPage>
    with AutomaticKeepAliveClientMixin {
  // StreamSubscription _upSubscription;
  List<UserIdNamePhoneEntity> downlistEntity = [];
  // MyTuanYouBloc _bloc;
  @override
  void initState() {
    super.initState();
    // _bloc = MyTuanYouBloc();
    // _bloc.initDate.add(null);
    // _upSubscription = eventBus.on<DownTuanyouListEvent>().listen((event) {
    //   setState(() {
    //     BaseConstant.downlistEntity = event.list;
    //   });
    // });
    downlistEntity = this.widget.downlistEntity;
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    return Container(
        decoration: BoxDecoration(
          color: Colors.white,
        ),
        child: _showlistView());
  }

  Widget _showlistView() {
    return ListView.builder(
      shrinkWrap: true,
      padding: const EdgeInsets.only(top: 4),
      itemCount: downlistEntity.length,
      itemBuilder: buildItem,
    );
  }

  //ListView的Item
  Widget buildItem(BuildContext context, int index) {
    return Container(
      // margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 8),
      child: _xunchaItem(downlistEntity[index]),
    );
  }

  Widget _xunchaItem(UserIdNamePhoneEntity entity) {
    return Container(
      decoration: BoxDecoration(
        color: Colors.transparent,
      ),
      alignment: FractionalOffset.centerLeft,
      child: Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          SizedBox(
            height: 4,
          ),
          WidgetUtils.itmeStyleView(entity.name, '¥ ${entity.tuiGuanFei}',
              isExpanded: false,
              contentAlignment: Alignment.centerRight,
              textColor: Colours.gray_91,
              contentColor: Colours.blackground_609,
              isContentExpanded: true),
          SizedBox(
            height: 8,
          ),
          WidgetUtils.itmeStyleView(entity.phone, entity.createDate,
              contentAlignment: Alignment.centerRight,
              isExpanded: false,
              isContentExpanded: true,
              contentColor: Colours.gray_91,
              textColor: Colours.gray_91),
          SizedBox(
            height: 4,
          ),
          WidgetUtils.drawCodeDivider(height: 1),
        ],
      ),
    );
  }

  @override
  bool get wantKeepAlive => true;

  @override
  void dispose() {
    //_upSubscription?.cancel();
    super.dispose();
  }
}
